home *** CD-ROM | disk | FTP | other *** search
- ;"Ftp" - Auto FTP/download script
-
- ;Script to read filenames from a text file, then ftp
- ;and download them, one at a time. Useful for those with small
- ;disk quotas.
- ;
- ;The idea is to give it a list of sites, directories, and files.
- ;It will then ftp to the first site, cd to the first dir, and get
- ;the first file, which it then downloads. It then deletes the first file,
- ;ftps to the second site, cds to the second directory, etc.
- ;It's not perfect, but I find it very useful. I tried to comment it
- ;as much as I could, but all the commenting was done after the whole
- ;thing was written, so I hope it all makes sense.
-
- ;Be sure the change the system prompt variable and the occurance
- ;of an e-mail address before compiling. To locate the single
- ;occurance of an e-mail address (currently mine - should be
- ;yours), search for the @ character.
-
- ;Shares a file with a companion script "ftptry" (file which
- ;contains names and working directories of favorite
- ;ftp sites.
- ;
- ;please send any comments, criticisms, complaints, praises, donations (haha) to
- ;Erick Hammersmark, ehammers@u.washington.edu
- ;
- string FtpSite,FtpDir,Ftpfile,ViewList
- string ListSite,ListDir,ListFile,ListEntry
- string PROMPT = "stein%",LookFile = "c:\prowin\file.txt" ;rember to change prompt to match your system
- string SiteList = "c:\prowin\sites.txt"
- integer NotDone = 1,Ftpdone = 0,index,length
-
- proc main
- call GetList ;enter new sites/dirs/files
- fopen 1 "c:\prowin\files.txt" READWRITE TEXT ;open file containing sites/dirs/files
- call ReadList
- while NotDone ;Loop until reaching the end of the text file.
- call InitFtp
- waitfor "ftp>" ;Login to the ftp server.
- transmit "bin^M"
- waitfor "ftp>" ;Set type to "binary".
- transmit "cd "
- transmit FtpDir
- transmit "^M"
- waitfor "ftp>" ;Cd to directory where file is stored.
- transmit "get "
- transmit FtpFile
- transmit "^M"
- waitfor "ftp>" forever ;Get the current file.
- transmit "quit^M"
- waitfor PROMPT ;End ftp session.
- transmit "sb " ;Command to download file
- transmit FtpFile ;may need to be altered to fit
- transmit "^M" ;alternate systems.
- waitfor "mode"
- pause 5
- getfile ymodem
- waitfor PROMPT forever ;download file
- transmit "rm "
- transmit FtpFile
- transmit "^M"
- waitfor PROMPT ;Delete downloaded file.
- call ReadList ;Get next filename.
- endwhile ;End of loop. Continues while NotDone is true.
- fclose 1 ;Close text file.
- transmit "logout^M"
- waitfor "cts" ;Command to logout may need to be
- transmit "exit^M" ;altered to fit alternate systems.
- hangup
- endproc
-
- proc ReadList ;procedure to read information from file.
- fgets 1 FtpSite ;read name of ftp site
- if feof 1 ;if at end of file
- NotDone = 0 ;NotDone is set to false, ending loop in "main"
- endif
- fgets 1 FtpDir ;read name of ftp directory
- fgets 1 FtpFile ;read name of ftp file
- endproc
-
- proc GetList ;procedure to enter sitenames, dirs, and filenames
- integer selection = 0 ;a variable to hold $DIALOG
- ;call LookList
- ;updatedlg 16
- dialogbox 123 40 185 194 6 "Late Night FTP"
- editbox 12 15 160 12 FtpSite ;230
- editbox 11 45 159 12 FtpDir ;231
- editbox 12 75 159 12 FtpFile ;232
- text 15 5 29 8 left "FTP site"
- text 15 35 33 8 left "Directory"
- text 15 67 36 8 left "Filename"
- pushbutton 12 98 40 14 "Add" update default ;30
- pushbutton 72 98 40 14 "Close" normal ;10
- pushbutton 131 98 40 14 "Go" normal ;11
- flistbox 6 121 168 50 LookFile single ListEntry ;130
- pushbutton 22 175 40 14 "Delete" update ;31
- pushbutton 119 175 40 14 "New" update ;32
- fcombobox 55 28 117 46 SiteList FtpSite sort ;190 combo box gets its list from a
- ; file it shares with "ftptry"
- enddialog
- while 1 ;loop forever
- selection = $DIALOG
- if selection == 30 ;if "add" is pressed
- fopen 0 "c:\prowin\files.txt" READWRITE TEXT ;open file
- fseek 0 0 2 ;go to end of file
- fputs 0 FtpSite
- fputs 0 FtpDir
- fputs 0 FtpFile ;write the site,dir,and filename
- fclose 0 ;close file
- call LookList
- updatedlg 16
- endif
- if selection == 10 ;if "close" is pressed
- exit ;exit script
- endif
- if selection == 11 ;if "go" is pressed
- destroydlg
- exitwhile ;leave the infinite "while" loop
- endif
- if selection == 31 ;if delete is pressed
- call ParseListEntry
- call DeleteItem
- call LookList
- updatedlg 16
- updatedlg 128
- endif
- if selection == 32 ;if "new" is pressed
- fopen 0 "c:\prowin\files.txt" CREATE TEXT ;erase old data file
- fclose 0 ;close file
- call LookList ;reread datafile
- updatedlg 16 ;update list box
- FtpSite = ""
- FtpDir = ""
- FtpFile = "" ;clear inputs
- updatedlg 128 ;update editboxes
- updatedlg 32 ;update fcombobox
- endif
- if selection == 130 ;if flistbox selection is made
- call ParseListEntry
- updatedlg 128
- endif
- if selection == 190 ;if fcombobox selection is made
- call GetWorkDir ;get new directory
- FtpFile = ""
- updatedlg 128 ;update editboxes
- endif
- endwhile
- endproc
-
- proc ReCall ;procedure to call an ftp site
- transmit "ftp "
- transmit FtpSite
- transmit "^M" ;call the ftp site
- endproc
-
- proc QuitFtp ;procedure to quit and recall an ftp site
- transmit "quit^M"
- waitfor PROMPT ;wait for system prompt (defined above)
- call ReCall
- endproc
-
- proc EndFtp ;cleans up after connect established
- FtpDone = 1 ;tells InitFtp to stop looping
- clearwhen target 0
- clearwhen target 1
- clearwhen target 2 ;clears all the "when target" statements
- endproc
-
- proc InitFtp
- call ReCall ;call ftp site
- when target 0 "530" call QuitFtp ;if it's busy, quit and try again
- when target 1 "):" call FtpLogin ;if faced with a login prompt, login as anonymous
- when target 2 "230" call EndFtp ;when logged in, call the EndFtp procedure
- while not FtpDone
- endwhile
- endproc
-
- proc FtpLogin ;procedure to login to ftp site
- pause 1
- transmit "anonymous^M"
- waitfor "Password:"
- transmit "ehammers@u.washington.edu^M" ;your e-mail address goes here
- endproc
-
- proc LookList ;creates new file for dlg box list to read
- string CharSpace = " " ;Variable for ","
- isfile "c:\prowin\files.txt"
- if success ;if source file exists
- fopen 2 "c:\prowin\files.txt" READ TEXT ;open it
- else ;if source file does not exist
- fopen 2 "c:\prowin\files.txt" CREATE TEXT ;create it to avoid errors
- endif
- fopen 3 "c:\prowin\file.txt" CREATE TEXT ;create (erase) temp file
- while 1 ;loop indefinitely
- ViewList = ""
- fgets 2 ListSite ;store site in variable
- if feof 2 ;if at end of file
- fclose 2
- fclose 3 ;close both files
- exitwhile ;and exit indefinite loop
- endif
- fgets 2 ListDir
- fgets 2 ListFile ;store dir and filename
- strcat ViewList ListSite
- strcat ViewList CharSpace
- strcat ViewList ListDir
- strcat ViewList CharSpace
- strcat ViewList ListFile ;concatenate site/dir/file
- fputs 3 ViewList ;write new string to temp file
- endwhile
- endproc
-
- proc GetWorkDir ;procedure to get working directory to suggest
- string FtpSiteTwo
- fopen 5 "c:\prowin\sitedirs.txt" READ TEXT ;open shared working directory file
- while 1
- fgets 5 FtpSiteTwo ;get next site name in file
- fgets 5 FtpDir ;get next working dir in file
- strcmp FtpSiteTwo FtpSite ;if site read from file = site selected in combo box
- if success
- exitwhile ;exit loop
- endif
- endwhile
- fclose 5
- endproc
-
- #comment
- When a user clicks on an entry in the flistbox,
- the entry's site, directory, and file appear in the
- edit boxes. Since the flistbox entry is stored as a
- single string, it must be separated into it's three
- component strings for insertion into the edit boxes
- #endcomment
-
- proc ParseListEntry ;procedure to parse list box entry
- string PreserveEntry
- PreserveEntry = ListEntry ;preserve original flistbox entry in string
- strlen ListEntry length ;take length of list entry
- strfind ListEntry " " index ;find first space
- strcpy FtpSite ListEntry index ;copy ListEntry to FtpSite using all characters until first space
- length = length - index
- dec length ;update length variable to include only the remaining part of ListEntry, minus the space
- strright ListEntry ListEntry length ;take the rightmost characters
- strfind ListEntry " " index ;find next space
- strcpy FtpDir ListEntry index ;copy ListEntry to FtpDir using first "length"th characters
- length = length - index
- dec length ;update length and subtract for space
- strright FtpFile ListEntry length ;take FtpFile from list entry
- ListEntry = PreserveEntry ;restore ListEntry variable
- endproc
-
- #comment
- This is probably the least efficient of all the routines in this
- script. In order to delete a single entry from the data files,
- it recompiles the whole list. Thus it is pretty slow with large
- lists. Sorry about this, but this was a hard feature to
- incoperate!
- #endcomment
-
- proc DeleteItem ;procedure to delete item from data file based on FListBox selection
- fopen 2 "c:\prowin\files.txt" READ TEXT ;open data file
- fopen 3 "c:\prowin\file.txt" CREATE TEXT ;create (overwrite) temp file
- while 1
- fgets 2 ListSite ;Get first site from data file
- if feof 2 ;if at the end of the data file
- fclose 2
- fclose 3
- delfile "c:\prowin\files.txt" ;delete old data file
- rename "c:\prowin\file.txt" "c:\prowin\files.txt" ;rename temp file to data file
- exitwhile ;exit loop
- endif
- fgets 2 ListDir ;get dir from data file
- fgets 2 ListFile ;get filename from data file
- strcmp ListFile FtpFile ;if filenames do not match
- if not success
- fputs 3 ListSite ;write data into temp file
- fputs 3 ListDir
- fputs 3 ListFile
- endif
- endwhile
- FtpSite = "" ;clear edit boxes to remove
- FtpDir = "" ;presence of unwanted entry.
- FtpFile = ""
- endproc
-